package com.yunyao.dao.service.bamu.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunyao.common.constant.enums.DataDeletedStatus;
import com.yunyao.dao.mapper.BamuReconciliationSettlementMapper;
import com.yunyao.dao.model.BamuReconciliationSettlement;
import com.yunyao.dao.model.BamuSpReconciliationSettlement;
import com.yunyao.dao.service.bamu.IBamuReconciliationSettlementService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 对账表 服务实现类
 * </p>
 *
 * @author xingjishuai
 * @since 2024-07-02
 */
@Service
public class BamuReconciliationSettlementServiceImpl extends ServiceImpl<BamuReconciliationSettlementMapper, BamuReconciliationSettlement> implements IBamuReconciliationSettlementService {

    /**
     * 根据ID和删除状态获取对账结算单
     * 此方法专注于通过ID检索未被逻辑删除的对账结算单，确保只处理有效数据
     *
     * @param id 对账结算单的唯一标识
     * @return 未被逻辑删除的对账结算单详情，如果不存在则返回null
     */
    @Override
    public BamuReconciliationSettlement getByIdAndDeleted(String id) {
        // 构建查询条件，筛选未被逻辑删除且ID匹配的数据
        LambdaQueryWrapper<BamuReconciliationSettlement> queryWrapper =
                new LambdaQueryWrapper<BamuReconciliationSettlement>()
                        .eq(BamuReconciliationSettlement::getIsDeleted,
                                DataDeletedStatus.NO.getType()).eq(BamuReconciliationSettlement::getId, id);
        // 执行查询并返回结果
        return getOne(queryWrapper);
    }


    @Override
    public List<BamuReconciliationSettlement> listById(String Id) {
        // 检查合同ID是否为空或空白，如果是，则返回一个空列表
        if (org.apache.commons.lang3.StringUtils.isBlank(Id)) {
            return List.of();
        }
        // 创建一个LambdaQueryWrapper用于构建查询条件
        LambdaQueryWrapper<BamuReconciliationSettlement> wrapper =
                new LambdaQueryWrapper<BamuReconciliationSettlement>().eq(BamuReconciliationSettlement::getId,
                        Id).eq(BamuReconciliationSettlement::getIsDeleted, DataDeletedStatus.NO.getType());
        // 使用构建的查询条件获取并返回关联的材料列表
        return list(wrapper);
    }
}
